

#import "RootViewController.h"
#import "MyLauncherItem.h"
#import "CustomBadge.h"
#import "ItemViewController.h"
#import "FMDBCollectionManager.h"
#import "Collection.h"
#import "UICustomImageView.h"
#import "MyLauncherViewController.h"
#import "Constants.h"


@implementation RootViewController

-(void)loadView
{    
//    NSString *filePath=[[NSBundle mainBundle] pathForResource:@"searchBarBg-d" ofType:@"png"];
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithContentsOfFile:filePath] forBarMetrics: UIBarMetricsDefault];
}



- (void)viewWillAppear:(BOOL)animated
{
[super loadView];
self.title = @"收藏";
[[self appControllers] setObject:[ItemViewController class] forKey:@"ItemViewController"];

FMDBCollectionManager *fmdbCollectionManager = [[FMDBCollectionManager alloc] init];
collectionArray = [fmdbCollectionManager getAllCollection];
    if([collectionArray count] == 0){
        UIImage *image = [UIImage imageNamed:@"collectionBg.png"];    
        self.view.layer.contents = (id) image.CGImage;
        // 如果需要背景透明加上下面这句
        //        topView.layer.backgroundColor = [UIColor clearColor].CGColor;
    }
    else{
        //第一页数组
        NSMutableArray *fArray=[[NSMutableArray alloc] initWithCapacity:SScollectionImg];
        
        //第二页数组
        NSMutableArray *sArray=[[NSMutableArray alloc] initWithCapacity:SScollectionImg];
        
        
        
        
        for(Collection *collection in collectionArray){
            if(collection.page==1){
                MyLauncherItem *temp= [[MyLauncherItem alloc] initWithTitle:collection.supplierName
                                                                iPhoneImage:collection.imgUrl 
                                                                  iPadImage:@"itemImage-iPad"
                                                                     target:[NSString stringWithFormat:@"%d",collection.supplierId] 
                                                                targetTitle:@"Item 11 View"
                                                                  deletable:YES];
                [fArray addObject:temp];
            }
            else{
                MyLauncherItem *temp2= [[MyLauncherItem alloc] initWithTitle:collection.supplierName
                                                                 iPhoneImage:collection.imgUrl 
                                                                   iPadImage:@"itemImage-iPad"
                                                                      target:[NSString stringWithFormat:@"%d",collection.supplierId] 
                                                                 targetTitle:@"Item 11 View"
                                                                   deletable:YES];
                [sArray addObject:temp2];
            }
        }
        if([sArray count]==0){
            [self.launcherView setPages:[NSMutableArray arrayWithObjects: fArray,nil]];
        }
        else{
            [self.launcherView setPages:[NSMutableArray arrayWithObjects: fArray,sArray,nil]];
        }
    }
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload 
{
    [super viewDidUnload];
}

@end
